Accessibility
Home / DevNet / Dreamweaver Development Center /
DevNet
Dreamweaver Article

Appendix B: DataSet Tag Methods
The FieldValue method of the DataSet tag takes two arguments: the name of the database column and the name of the container. By default, it returns data from the first row in DataSet. This is fine for your example because the SELECT statement used in DataSet returns a single row. (So long as the table has a UNIQUE attribute attached to the emailaddr field so you know that you'll always get only one row when you do a SELECT with a WHERE clause that specifies the e-mail address and password.)

Use the FieldValueAtIndex method if you want a specific row within DataSet that returns multiple rows. This method takes three arguments: the row number (zero-indexed), the database column, and the name of the container.

Because your dataset has just one row, the following two lines are equivalent:

DS_uidAndPwd.FieldValue("emailaddr", null)
DS_uidAndPwd.FieldValueAtIndex(0, "emailaddr", null)

The last argument for both methods is the name of the container. You use either the word "Container" or "null." If the call to FieldValue or FieldValueAtIndex is within a DataGrid, DataList, or Repeater tag, then use "Container." Otherwise, use "null." In your case, you're calling FieldValue from the Page_Load function: You don't have a container, so you can use "null" as the last argument.

Note: If you are curious about the meaning of "Container," you can look at the Microsoft documentation for the Eval method of the DataBinder class. The "Container" used in FieldValue and FieldValueAtIndex is identical to the "Container" used when you call DataBinder.Eval.

You're probably wondering when to use "Container." Here's a quick example: You have a page with DataGrid. The data source for DataGrid is DataSet. Each row of DataGrid corresponds to a row in DataSet. Let's say you use DataGrid to list your e-mail addresses and you want the text to be a mailto link to the e-mail address. You can do this in Dreamweaver MX by changing the column datatype from Simple Data Field to Free Form. This allows you to use an ItemTemplate. This is where you use the FieldValue("column", Container) form of the method:

<asp:TemplateColumn HeaderText="emailaddr" Visible="True">
  <ItemTemplate>
            <%# 
  "<a href='mailto:" + 
DS_members.FieldValue("emailaddr", Container) + "'>" + 
DS_members.FieldValue("emailaddr", Container) + 
               "</a>"
%>
  </ItemTemplate>
</asp:TemplateColumn>

In this example, using Container in the call to FieldValue ensures that you use the appropriate dataset row. Here's what you will see:

Result of using FieldValue method within the DataGrid container
 

You can use the DataSet tag and its methods in a wide variety of situations. At its core, though, it provides a tag-based method for creating sets of records from a database. You can obtain the records using T-SQL statements directly or by specifying the name of a stored procedure. Once acquired, the records can be used as the data source for DataGrids (as shown in the brief example above). In addition, you can access specific values of the DataSet tag using the FieldValue and FieldValueAtIndex methods. This application was discussed previously in the section "The DataSet tag."

 
 
Previous Contents